const { getAll, update, add, remove } = require('../utils/dbTools')
const tableName = 'banner'

/**
 * 获取轮播图列表 
 * @param {object} map 查询条件
 */
const getBannerList = async (map) => {
    if (!map) return false
    const result = await getAll(tableName, map)
    return result
}


/**
 * 新增轮播图
 * @param {object} options 轮播图数据对象   
 */
const addBanner = async (options) => {
    if (!options) return false
    const result = await add(options, tableName)
    return result
}


/**
 * 更新轮播图
 * @param {object} options 轮播图数据对象   
 */
const updateBanner = async (options) => {
    const { id } = options;
    if (!id) return false
    const data = { ...options }
    delete data.id
    const result = await update(id, data, tableName)
    return result
}

/**
 * 删除轮播图
 * @param {number} id 轮播图id
 */
const removeBanner = async (id) => {
    if (!id) return false
    const result = await remove(id, tableName)
    return result
}

module.exports = {
    getBannerList, addBanner, updateBanner, removeBanner
}